package com.wyzz.hr.action;

import java.util.List;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.base.DWRUtil;
import com.wyzz.hr.bo.IBenefitTypeBO;
import com.wyzz.hr.bo.ILocationBO;
import com.wyzz.hr.pojo.BenefitType;
import com.wyzz.hr.pojo.Location;
import com.wyzz.hr.spring.SpringBeanFactory;

public class BenefitTypeList extends BaseAction {

	public BenefitTypeList() {
	}

	public String execute() throws Exception {
		bfTypeList = getDrillDown("BenefitType", new String[0]);
		locList = getDrillDown("Location", new String[] { "1" });
		return "success";
	}

	public String addBenefitType(String locationId, BenefitType benefitType) {
		String auth = DWRUtil.checkAuth("benefitTypeList", "execute");
		if ("error".equals(auth))
			return "noauth";
		IBenefitTypeBO bfTypeBo = (IBenefitTypeBO) SpringBeanFactory
				.getBean("benefitTypeBo");
		ILocationBO localbo = (ILocationBO) SpringBeanFactory
				.getBean("locationBO");
		Location location = localbo.loadLocation(locationId);
		benefitType.setBenefitTypeLocNo(location);
		List list = bfTypeBo.findNameByobj(benefitType);
		if (list.size() > 0)
			return "EXISTED";
		if (bfTypeBo.addBenefitType(benefitType))
			return benefitType.getId();
		else
			return "FAIL";
	}

	public String delBenefitType(String id) {
		String auth = DWRUtil.checkAuth("benefitTypeList", "execute");
		if ("error".equals(auth))
			return "noauth";
		try {
			IBenefitTypeBO bfTypeBo = (IBenefitTypeBO) SpringBeanFactory
					.getBean("benefitTypeBo");
			if (bfTypeBo.delBenefitType(BenefitType.class, id))
				return "SUCC";
		} catch (Exception e) {
			return "error";
		}
		return "FAIL";
	}

	public String saveBenefitTypeSortIdByBatch(String ids[]) {
		String auth = DWRUtil.checkAuth("benefitTypeList", "execute");
		if ("error".equals(auth))
			return "noauth";
		IBenefitTypeBO bfTypeBo = (IBenefitTypeBO) SpringBeanFactory
				.getBean("benefitTypeBo");
		if (bfTypeBo.saveBenefitTypeSortIdByBatch(ids))
			return "SUCC";
		else
			return "FAIL";
	}

	public String updateBenefitType(String locationId, BenefitType benefitType) {
		String auth = DWRUtil.checkAuth("benefitTypeList", "execute");
		if ("error".equals(auth))
			return "noauth";
		IBenefitTypeBO bfTypeBo = (IBenefitTypeBO) SpringBeanFactory
				.getBean("benefitTypeBo");
		BenefitType dbBenefitType = bfTypeBo.searchById(benefitType.getId());
		if (dbBenefitType == null)
			return "FAIL";
		List list = bfTypeBo.findSameNameByobj(benefitType);
		if (list.size() > 0)
			return "EXISTED";
		dbBenefitType.setBenefitTypeLocNo(new Location(locationId));
		dbBenefitType.setBenefitTypeDescription(benefitType
				.getBenefitTypeDescription());
		dbBenefitType.setBenefitTypeName(benefitType.getBenefitTypeName());
		dbBenefitType
				.setBenefitTypePayType(benefitType.getBenefitTypePayType());
		dbBenefitType.setBenefitTypeSortId(benefitType.getBenefitTypeSortId());
		dbBenefitType.setEbfTypeChildbirthLowlimit(benefitType
				.getEbfTypeChildbirthLowlimit());
		dbBenefitType.setEbfTypeChildbirthUplimit(benefitType
				.getEbfTypeChildbirthUplimit());
		dbBenefitType.setEbfTypeHousingLowlimit(benefitType
				.getEbfTypeHousingLowlimit());
		dbBenefitType.setEbfTypeHousingUplimit(benefitType
				.getEbfTypeHousingUplimit());
		dbBenefitType.setEbfTypeInjuryLowlimit(benefitType
				.getEbfTypeInjuryLowlimit());
		dbBenefitType.setEbfTypeInjuryUplimit(benefitType
				.getEbfTypeInjuryUplimit());
		dbBenefitType.setEbfTypeMedicareLowlimit(benefitType
				.getEbfTypeMedicareLowlimit());
		dbBenefitType.setEbfTypeMedicareUplimit(benefitType
				.getEbfTypeMedicareUplimit());
		dbBenefitType.setEbfTypeOtherLowlimit(benefitType
				.getEbfTypeOtherLowlimit());
		dbBenefitType.setEbfTypeOtherUplimit(benefitType
				.getEbfTypeOtherUplimit());
		dbBenefitType.setEbfTypePensionLowlimit(benefitType
				.getEbfTypePensionLowlimit());
		dbBenefitType.setEbfTypePensionUplimit(benefitType
				.getEbfTypePensionUplimit());
		dbBenefitType.setEbfTypeUnemploymentLowlimit(benefitType
				.getEbfTypeUnemploymentLowlimit());
		dbBenefitType.setEbfTypeUnemploymentUplimit(benefitType
				.getEbfTypeUnemploymentUplimit());
		if (bfTypeBo.updateBenefitType(dbBenefitType))
			return "SUCC";
		else
			return "FAIL";
	}

	public List getBfTypeList() {
		return bfTypeList;
	}

	public void setBfTypeList(List bfTypeList) {
		this.bfTypeList = bfTypeList;
	}

	public List getLocList() {
		return locList;
	}

	public void setLocList(List locList) {
		this.locList = locList;
	}

	private static final long serialVersionUID = 1L;
	private List bfTypeList;
	private List locList;
}
